package com.junci.mtest.utils;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.junci.mtest.R;


public class MainTabView extends LinearLayout {
    ImageView mainTabIv;
    TextView mainTabTv;
    private int type;
    private boolean isCheck;
//    private static final int TYPE_FAST = 0;
//    private static final int TYPE_KE = 1;
//    private static final int TYPE_HOHO = 2;
//    private static final int TYPE_MINE = 3;

    private static final String[] tabs = {"首页","课程","Hoho","我的"};

    public MainTabView(Context context) {
        this(context, null, -1);
    }
    public MainTabView(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }
    public MainTabView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MainTabView, defStyleAttr, 0);
        type = typedArray.getInt(R.styleable.MainTabView_tab_type, 0);
        isCheck = typedArray.getBoolean(R.styleable.MainTabView_is_check,false);
        typedArray.recycle();
        initView();
    }
    private void initView() {
        View inflate = View.inflate(getContext(), R.layout.view_main_tab_view, this);
        mainTabIv = (ImageView) inflate.findViewById(R.id.main_tab_iv);
        mainTabTv = (TextView) inflate.findViewById(R.id.main_tab_tv);
        setChecked(isCheck);
        setClickable(true);
    }
    public void setText(String text){
        mainTabTv.setText(text);
    }
    public void setChecked(boolean isCheck){
        if(isCheck){
            mainTabIv.setImageResource(R.mipmap.icon_main_y);
            mainTabTv.setTextColor(getResources().getColor(R.color.black));
        }else{
            mainTabIv.setImageResource(R.mipmap.icon_main_n);
            mainTabTv.setTextColor(getResources().getColor(R.color.gray));
        }
        mainTabTv.setText(tabs[type]);
    }
}

